package com.sunjob.mroassets.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.sunjob.common.result.Result;
import com.sunjob.mroassets.server.TimeService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
@Api(tags = "实体剩余寿命服务接口")
public class TimeController {
    @Autowired
    TimeService timeService;
    @ApiOperation("实体寿命查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "实体类型",name = "type")
    })//描述入参信息
    @ApiResponses({
            @ApiResponse(code = 404,message = "无此路径"),
            @ApiResponse(code = 500,message = "服务内部错误"),
            @ApiResponse(code = 200,message = "访问成功")
    })
    //通过类型查询实体的寿命列表，传入要查询的类型
    @RequestMapping("/getEntityTime")
    public Result getTypeTime(@RequestParam("type") String type){
        Result result = new Result();
        //调用服务层，通过实体类型查询实体列表，并传入返回数据集中
        result.setData(timeService.getTypeTime(type));
        return result;
    }
    @ApiOperation("按照实体寿命类型查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "实体类型",name = "type"),
            @ApiImplicitParam(value = "寿命类型",name = "timeType")
    })//描述入参信息
    @ApiResponses({
            @ApiResponse(code = 404,message = "无此路径"),
            @ApiResponse(code = 500,message = "服务内部错误"),
            @ApiResponse(code = 200,message = "访问成功")
    })
    //通过类型以及寿命类型查询实体的寿命列表，传入要查询的类型
    @RequestMapping("/getEntityByTypeAndTime")
    public Result getEntityTimeByLimity(@RequestParam("type") String type,@RequestParam("time") Integer timeType){
        Result result = new Result();
        //调用服务层，通过实体类型以及寿命类型查询实体列表，并传入返回数据集中
        result.setData(timeService.getEntityTimeByLimity(type,timeType));
        return result;
    }
    //定时修改数据库中实体的使用寿命
    //触发时间为每天的上午八点
    @Scheduled(cron = "0 0 8 * * ?")
    public void timeTask(){
        //调用服务层进行处理
        timeService.updateEntityTime();
    }
}
